2356. 每位教师所教授的科目种类的数量
# Write your MySQL query statement below
select
    teacher_id,
    count(distinct subject_id) as cnt
from
    Teacher
group by
    teacher_id


1141. 查询近30天活跃用户数
# Write your MySQL query statement below
select
    activity_date as day,
    count(distinct user_id) as active_users
from 
    Activity 
where
    activity_date between date_sub("2019-07-27",interval 29 day) and "2019-07-27"
group by
    activity_date

150. 逆波兰表达式求值
class Solution 
{
bool isOperator(string ch)
{
    if(ch == "+"|| ch == "-"|| ch == "*" || ch == "/")
    {
        return true;
    }
    return false;
}

int calculate(int former,int latter,string op)
{
    if(op=="+")
    {
        return former + latter;
    }
    else if(op == "-")
    {
        return former - latter;
    }
    else if(op == "*")
    {
        return former * latter;
    }
    else if(op == "/")
    {
        if(latter==0)
        {
            return INT_MIN;
        }
        return former/latter;
    }
    else 
    {
        return INT_MIN;
    }
}

public:
    int evalRPN(vector<string>& tokens) 
    {
        stack<int> num;

        for(int i=0;i<tokens.size();i++)
        {
            string& tmp = tokens[i];
            if(isOperator(tmp))
            {
                if(num.size()>=2)
                {
                    int latter = num.top();
                    num.pop();
                    int former = num.top();
                    num.pop();
                    int ret = calculate(former,latter,tmp);
                    num.push(ret);
                }
                else 
                {
                    cout << "illegal operator!"<<endl;
                    break;
                }

            }
            else 
            {
                int number = stoi(tmp);
                num.push(number);
            }
        }    
        
        return num.top();
    }
};


1084. 销售分析 III

# Write your MySQL query statement below
select
    Product.product_id,
    Product.product_name
from
    Product   
where Product.product_id in 
(
    select 
        distinct product_id
    from
        Sales
    group by
        product_id
    having 
        min(sale_date) >= "2019-01-01" and max(sale_date) <= "2019-03-31"
        
)
